var express = require('express');
var router = express.Router();
var {userModel,renwuModel} = require("../model/model")
var jwt = require("jsonwebtoken");

/* GET home page. */
// 登录
router.post("/login", async (req, res) => {
  let [user] = await userModel.find({ username: req.body.username })
  if (user) {
    if (user.password == req.body.password) {
      let token = "Bearer " + " " + jwt.sign({ id: user._id }, 'flag')
      res.send({
        code: 200,
        msg: "登录成功",
        token
      })
    } else {
      res.send({
        code: 400,
        msg: "密码错误"
      })
    }
  } else {
    res.send({
      code: 400,
      msg: "用户不存在"
    })
  }
})


module.exports = router;
